/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.util.Collection;
import java.util.HashSet;

/**
 *
 * @author wkhim
 */
public class Pays {

    private Collection<Dep> lesDeps = new HashSet<Dep>();
    private Collection<Spe> lesSpes = new HashSet<Spe>();
    private Collection<Med> lesMeds = new HashSet<Med>();

    public Pays() {
        // choisir DAO pour PostGreSQL sinon DAOMySQL pour MySQL
//        lesDeps = DAO.getLesDeps();
//        lesMeds = DAO.getLesMeds();
//        lesSpes = DAO.getLesSpes();
        lesDeps = DAOMySQL.getLesDeps();
        lesMeds = DAOMySQL.getLesMeds();
        lesSpes = DAOMySQL.getLesSpes();
        remplirColl();
    }

    public Collection<Dep> getLesDeps() {
        return lesDeps;
    }

    public Collection<Spe> getLesSpes() {
        return lesSpes;
    }

    public Collection<Med> getLesMeds() {
        return lesMeds;
    }

    public void remplirColl() {
        for (Med unMed : lesMeds) {
            getLeDep(unMed.getDep()).ajouterMed(unMed);
            if (getLeSpe(unMed.getSpe()) != null) {
                getLeSpe(unMed.getSpe()).ajouterMed(unMed);
            }
        }
    }

    public Dep getLeDep(String numDep) {
        for (Dep unDep : lesDeps) {
            if (unDep.getNum().equals(numDep)) {
                return unDep;
            }
        }
        return null;
    }

    public Spe getLeSpe(String libSpe) {
        for (Spe unSpe : lesSpes) {
            if (unSpe.getLibelle().equals(libSpe)) {
                return unSpe;
            }
        }
        return null;
    }

    public Med getLeMed(String nomMed) {
        for (Med unMed : lesMeds) {
            if (unMed.getNom().equals(nomMed)) {
                return unMed;
            }
        }
        return null;
    }
}
